package com.zou.jokes.sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.zou.jokes.Constant;


/**
 * Created by zou on 2016/3/14.
 */
public class MySqliteOpenHelper extends SQLiteOpenHelper {
    public MySqliteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    public MySqliteOpenHelper(Context context) {
        super(context, Constant.tableName, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
//        addTime,content,hashID,unixtime,updatetime,url
        String sql = "create table if not exists " + Constant.tableName + " (addTime long primary key ,hashID String, content String,unixtime long, updatetime String, url String)";
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        String sql = "DROP TABLE IF EXISTS " + Constant.tableName;
        db.execSQL(sql);
        onCreate(db);
    }
}
